<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="topbar::static">

<body>

<nav th:replace="topbar::topbar"></nav>

<div class="container-fluid">
    <div class="row">
        <div th:replace="topbar::sidebar(activeUri='vnfdf.html')"></div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <h1 class="page-header">5GC MANO</h1>
            <button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bs-example-modal-lg">
                新增VNF部署风格
            </button>
            <div class="table-responsive">
                <table class="table table-striped">
                    <thead>
                    <tr>
                        <th>flavourId</th>
                        <th>description</th>
                        <th>vduProfile</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr th:each="vnfdf:${vnfdfs}">
                        <td th:text="${vnfdf.flavourId}"></td>
                        <td th:text="${vnfdf.description}"></td>
                        <td th:text="${vnfdf.vduProfile}"></td>
                        <td>
                            <button type="button" class="btn btn-danger" aria-label="Left Align"
                                    th:onclick="|deleteVnfdf(${vnfdf.flavourId})|">
                                <span class="glyphicon glyphicon-remove"></span>
                            </button>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<!--模态框，用于新增VNF部署风格-->
<div id="modal_block" class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog"
     aria-labelledby="myLargeModalLabel">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">新增VNF部署风格</h4>
            </div>
            <div class="modal-body">
                <table class="table table-striped">
                    <div class="table-responsive">
                        <thead>
                        <tr>
                            <th>flavourId</th>
                            <th>description</th>
                            <th>vduProfile</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <td><input type="text" class="form-control" id="flavourId"></td>
                            <td><input type="text" class="form-control" id="description"></td>
                            <td>
                                <select id="vduProfile" class="selectpicker" multiple>
                                    <option class="form-control" th:each="vdup:${vdups}"
                                            th:value="${vdup.vduProfileId}">
                                        vduId:<span th:text="${vdup.vduId}"></span>+
                                        minInstance:<span th:text="${vdup.minNumberOfInstances}"></span>+
                                        maxInstance:<span th:text="${vdup.maxNumberOfInstances}"></span>+
                                        亲和性组：<span th:text="${vdup.affinityOrAntiAffinityGroupId}"></span>+
                                        节点亲和性：<span th:text="${vdup.localAffinityOrAntiAffinityRuleId}"></span>
                                    </option>
                                </select>
                            </td>
                        </tr>
                        </tbody>
                    </div>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="createVnfdf()">保存</button>
            </div>
        </div>
    </div>
</div>

<script>
    var baseUrl = "http://"+hostIp+":8004/vnfdf/";

    function createVnfdf() {
        var url = baseUrl + "create";
        $.ajax({
            url: url,
            type: "POST",
            data: {
                "flavourId": $("#flavourId").val(),
                "description": $("#description").val(),
                "vduProfile": $("#vduProfile").val().join(",")
            },
            complete: function (flavourId) {
                alert("vnfdf创建成功");
                reload();
            }
        });
    }

    function deleteVnfdf(flavourId) {
        //异步删除nsd
        var url = baseUrl + "delete";
        $.ajax({
            url: url,
            type: "POST",
            data: {
                "flavourId": flavourId
            },
            complete: function (flavourId) {
                alert("vnfdf删除成功");
                reload();
            }
        });
    }

    function reload() {
        $("#modal_block").modal('hide');
        window.location.reload();
    }
</script>
</body>
</html>
